/**
 * Licensed under the MIT License
 *
 * Copyright (c) 2010 Alexandre Croiseaux
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */
package marcel.events
{
	import flash.events.Event;
	
	/**
	 * StateEvent dispatched by a StateManager when transition or loading process happens in the StateManager
	 * @author Alexandre Croiseaux
	 * @see marcel.core.StateManager
	 */
	public final class StateEvent extends Event
	{
		//--------------------------------------------------------------------------
		//
		//  Public vars
		//
		//--------------------------------------------------------------------------
		/**
		 * The id of the previous active State in the StateManager
		 * States ids are defined in the settings XML file (/xml/settings.xml)
		 */
		public var previousStateId:String;
		/**
		 * The id of the current active State in the StateManager
		 * States ids are defined in the settings XML file (/xml/settings.xml)
		 */
		public var currentStateId:String;
		/**
		 * The id of the next State which must be active at the end of loading/transition process
		 * States ids are defined in the settings XML file (/xml/settings.xml)
		 */
		public var nextStateId:String;
		/**
		 * The id of the UI. Only set if type is START_UI_OPEN/START_UI_CLOSE/END_UI_OPEN/END_UI_CLOSE
		 * UIs ids are defined in the settings XML file (/xml/settings.xml)
		 */
		public var UIId:String;
		/**
		 * An optional object that has been passed to the StateManager.setState method
		 */
		public var params:Object;
		
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		/**
		 * Constructs a new StateEvent instance
		 * @param	type			type of the event, must be a constant of StateEvent class
		 * @param	previousStateId	id of the previous active State in the StateManager
		 * @param	currentStateId	id of the current active State in the StateManager
		 * @param	nextStateId		id of the next State which must be active at the end of loading/transition process
		 * @param	UIId			The id of the UI. Only set if type is START_UI_OPEN/START_UI_CLOSE/END_UI_OPEN/END_UI_CLOSE
		 * @param	params			An optional object will has been passed to the StateManager.setState method
		 * @param	bubbles			Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
		 * @param	cancelable		Determines whether the Event object can be canceled. The default values is false.
		 */
		public function StateEvent(type:String, previousStateId:String = null, currentStateId:String = null, nextStateId:String = null, UIId:String = null, params:Object = null, bubbles:Boolean = false, cancelable:Boolean = false)
		{
			super(type, bubbles, cancelable);
			this.previousStateId = previousStateId;
			this.currentStateId = currentStateId;
			this.nextStateId = nextStateId;
			this.UIId = UIId;
			this.params = params;
		}
		
		
		//--------------------------------------------------------------------------
		//
		//  Public methods
		//
		//--------------------------------------------------------------------------
		/**
		 * overriding clone method for event redispatching
		 * @return 	a clone of the current event
		 */
		override public function clone():Event
		{
			return new StateEvent(type, previousStateId, currentStateId, nextStateId, UIId, params, bubbles, cancelable);
		}
		
		/**
		* Dispatched by the StateManager when the loading of a State starts (State assets and State file)
		* @eventType	onStartLoadingState
		*/
		static public const START_LOADING_STATE:String = "onStartLoadingState";
		
		/**
		* Dispatched by the StateManager when the loading of a State is complete (State assets and State file)
		* @eventType	onEndLoadingState
		*/
		static public const END_LOADING_STATE:String = "onEndLoadingState";
		
		/**
		* Dispatched by the StateManager just before a State starts its opening animation
		* @eventType	onStartStateOpen
		*/
		static public const START_STATE_OPEN:String = "onStartStateOpen";
		
		/**
		* Dispatched by a State when its closing animation is complete
		* @eventType	onEndStateOpen
		*/
		static public const END_STATE_OPEN:String = "onEndStateOpen";
		
		/**
		* Dispatched by the StateManager just before a State starts its closing animation
		* @eventType	onStartStateClose
		*/
		static public const START_STATE_CLOSE:String = "onStartStateClose";
		
		/**
		* Dispatched by a State when its closing animation is complete
		* @eventType	onEndStateClose
		*/
		static public const END_STATE_CLOSE:String = "onEndStateClose";
		
		/**
		* Dispatched by a UI when its opening animation starts
		* @eventType	onStartUIOpen
		*/
		static public const START_UI_OPEN:String = "onStartUIOpen";
		
		/**
		* Dispatched by a UI when its opening animation is complete
		* @eventType	onEndUIOpen
		*/
		static public const END_UI_OPEN:String = "onEndUIOpen";
		
		/**
		* Dispatched by a UI when its closing animation starts
		* @eventType	onStartUIClose
		*/
		static public const START_UI_CLOSE:String = "onStartUIClose";
		
		/**
		* Dispatched by a UI when its closing animation is complete
		* @eventType	onEndUIClose
		*/
		static public const END_UI_CLOSE:String = "onEndUIClose";
	}
}